{extend name="admin/public/base" /}

{block name="content"}
<!-- Content Header (Page header) -->
<section class="content-header">
  <h1>
    创建规则
    <small></small>
  </h1>
  <ol class="breadcrumb">
    <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
    <li><a href="#">系统</a></li>
    <li class="active">创建规则</li>
  </ol>
</section>

<!-- Main content -->
<section class="content">
        <div class="box box-solid">
            <form method="post" id="form" action="" class="form-horizontal">
              <!-- Custom Tabs -->
              <div class="nav-tabs-custom">
                <ul class="nav nav-tabs">
                  <li class="active"><a href="#tab_1" data-toggle="tab" aria-expanded="true">基本信息</a></li>
                  <li class="pull-right"><a href="#" class="text-muted"><i class="fa fa-gear"></i></a></li>
                </ul>
                <div class="tab-content">
                  <div class="tab-pane active" id="tab_1">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">上级</label>
                            <div class="col-sm-2">
                                <select class="form-control" name="parent_id">
                                    <option value="0">根分类</option>
                                    {volist name="data" id="vo"}
                                    <option value="{$vo.id}">{$vo.html}{$vo.name}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">名称</label>
                            <div class="col-sm-4">
                                <input type="text" name="name" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">模块</label>
                            <div class="col-sm-4">
                                <input type="text" name="module" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">控制器</label>
                            <div class="col-sm-4">
                                <input type="text" name="controller" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">方法</label>
                            <div class="col-sm-4">
                                <input type="text" name="action" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">显示</label>
                            <div class="col-sm-5">
                                <label class="radio-inline">
                                    <input type="radio" name="is_menu" value="1"> 显示
                                </label>
                                <label class="radio-inline">
                                    <input type="radio" name="is_menu" checked value="0"> 隐藏
                                </label>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">排序</label>
                            <div class="col-sm-2">
                                <input type="text" name="reorder" class="form-control">
                            </div>
                        </div>
                  </div>
                  <!-- /.tab-pane -->
                </div>
                <!-- /.tab-content -->
                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        <div class="btn-group">
                            <button class="btn btn-default btn-flat" type="reset">取消</button>
                            <button class="btn btn-primary btn-flat" id="submit" type="submit">保存</button>
                        </div>
                    </div>
                </div>
              </div>
              <!-- nav-tabs-custom -->
            </form>
        </div>

</section>
<!-- /.content -->
{/block}

{block name="js"}
<script>

    $(function(){

        $("#form").validate({
            errorElement: 'span',  
            errorClass: 'help-block',  
            rules: {
                name: {
                    required: true,
                    maxlength: 64
                },
                module: {
                    required: true,
                    maxlength: 64
                },
                controller: {
                    required: true,
                    maxlength: 64
                },
                action: {
                    required: true,
                    maxlength: 64
                }
            },
            highlight : function(element) {  
                $(element).closest('.form-group').addClass('has-error');  
            },
            success : function(label) {  
                label.closest('.form-group').removeClass('has-error');  
                label.remove();
            },  
            submitHandler: function(form) {
                <!-- alert("submitted!"); -->
                $.ajax({
                    url:"{:url('admin/rule/store')}",
                    data:$(form).serialize(),
                    type:'post',
                    dataType:'json',
                    success:function(xhr){
                        if(xhr.code == 200){
                            swal({
                                title: xhr.msg,
                                text: "",
                                type: "success",
                                confirmButtonText: '确定',
                                cancelButtonText: '取消',
                            });
                        } else{
                            swal({
                                title: xhr.msg,
                                text: "",
                                type: "error",
                                confirmButtonText: '确定',
                                cancelButtonText: '取消',
                            });
                        }
                    }
                });

            }
        });

    });
</script>
{/block}